package com.hmall.order.web;

import com.hmall.common.feign.UserClient;
import com.hmall.common.pojo.User;
import com.hmall.order.pojo.Order;
import com.hmall.order.pojo.OrderDto;
import com.hmall.order.service.IOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private IOrderService orderService;
    @Autowired
    private UserClient userClient;
    /**
     * 根据id 获取订单信息
     * @param orderId
     * @return
     */
    @GetMapping("/{id}")
    public Order queryOrderById(@PathVariable("id") Long orderId, HttpServletRequest request) {
        Order order = orderService.getById(orderId);
        User user = userClient.findById(order.getUserId());
        String authorization = request.getHeader("authorization");
        log.warn("-->order authorization:{}",authorization );
        String test = request.getHeader("test");
        log.warn("-->order test:{}",test );
        return order;
    }

    @PostMapping
    public Long createOrder(@RequestBody OrderDto orderDto){
        Long orderId = orderService.createOrder(orderDto);


        return null;
    }
}
